package com.zhuss.product.processor;

import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.product.hotLineSite.CreateHotLineSiteBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.product.db.dao.ext.HotLineSiteDao;
import com.zhuss.product.db.entity.HotLineSite;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.DzcxException;
import com.zhuss.util.JsonUtil;


/**
 * @description: 热门线路站点创建
 * @author: zhushanshuo
 * @create: Mon Jan 11 09:22:02 CST 2021
 **/
@Component("hotLineSiteCreate")
public class HotLineSiteCreate extends AbstractProcessor<Object, CreateHotLineSiteBo> implements Processor<Object, CreateHotLineSiteBo> {

    @Autowired
    private HotLineSiteDao hotLineSiteDao;
    
    @Autowired
	@Qualifier("hotLineSiteRead")
	private HotLineSiteRead hotLineSiteRead;
    
    
    /**
     * 校验
     */
    @Override
    public void check(CreateHotLineSiteBo bo) throws DzcxException {
    	// TODO 创建 热门线路站点 校验， 请补充
//    	String name = bo.getName();
//    	if (name == null || "".equals(name.trim())) {
//    		// throw new DzcxException(ExceptionCode.热门线路站点name为空);
//    	}
//
//    	List<HotLineSite> list = hotLineSiteRead.list(name);
//    	if (!list.isEmpty()) {
//    		// throw new DzcxException(ExceptionCode.热门线路站点name已存在);
//    	}
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(CreateHotLineSiteBo param) {
    	HotLineSite record = new HotLineSite();
    	record.setHotLineId(param.getHotLineId());
    	record.setSiteId(param.getSiteId());
    	record.setPrice(param.getPrice());
    	record.setDistance(param.getDistance());
    	record.setNearestPrice(param.getNearestPrice());
    	record.setNearestDistance(param.getNearestDistance());
    	record.setSort(param.getSort());

    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	hotLineSiteDao.create(record);
    	param.setTargetId(record.getHotLineSiteId());
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(CreateHotLineSiteBo param) throws DzcxException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.商品.key());
    	record.setAction(LogActionEnum.热门线路站点绑定.key());
    	record.setTargetId(param.getTargetId());
    	record.setTargetName(param.getHotLineId()+"");
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
